<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple Chart.js本地测试</title>
    <!-- 只引入simple_chart.js -->
    <script src="/static/js/simple_chart.js"></script>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            height: 100vh;
            margin: 0;
        }
        .chart-container {
            width: 500px;
            height: 300px;
            margin: 20px;
        }
    </style>
</head>
<body>
    <h1>Simple Chart.js本地测试</h1>
    <div id="main-content">
        <div class="chart-container">
            <canvas id="testChart"></canvas>
        </div>
    </div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            console.log('测试页面已加载');
            
            // 使用simple_chart.js提供的waitForChart函数
            window.waitForChart(function(Chart) {
                console.log('通过waitForChart获取到Chart对象');
                
                try {
                    const ctx = document.getElementById('testChart').getContext('2d');
                    const testChart = new Chart(ctx, {
                        type: 'bar',
                        data: {
                            labels: ['A', 'B', 'C', 'D', 'E'],
                            datasets: [{
                                label: '测试数据',
                                data: [12, 19, 3, 5, 2],
                                backgroundColor: 'rgba(54, 162, 235, 0.7)'
                            }]
                        },
                        options: {
                            responsive: true,
                            maintainAspectRatio: false
                        }
                    });
                    
                    console.log('图表创建成功');
                    document.body.innerHTML += '<div style="color: green; text-align: center;">图表创建成功！</div>';
                } catch (error) {
                    console.error('图表创建失败:', error);
                    document.body.innerHTML += '<div style="color: red; text-align: center;">图表创建失败: ' + error.message + '</div>';
                }
            });
        });
    </script>
</body>
</html>